package com.portal.module.userRegister.service;

import com.portal.module.userRegister.dao.UserRegisterDao;
import com.portal.module.userRegister.entity.UserRegister;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.portal.admin.utils.admin.StringUtils;
import com.portal.admin.utils.admin.ObjectUtils;
import com.portal.admin.base.entity.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

//注册信息接口类
@Service
public class UserRegisterService extends BaseService {

    @Autowired
    private UserRegisterDao userRegisterDao;

    //【注册信息】设置查询条件
    private LambdaQueryWrapper<UserRegister> getUserRegisterQueryCondition(UserRegister userRegister) {
        LambdaQueryWrapper<UserRegister> lambdaQuery = this.getBaseQueryCondition(userRegister);
        //根据创建时间排序
        lambdaQuery.orderByDesc(UserRegister::getCreateDate);
        if (ObjectUtils.isNotNull(userRegister)) {
            //【主键id】精确查询
            lambdaQuery.eq(StringUtils.isNotEmpty(userRegister.getId()), UserRegister::getId, userRegister.getId());
            //【登录名】模糊查询
            lambdaQuery.like(StringUtils.isNotEmpty(userRegister.getLoginName()), UserRegister::getLoginName, userRegister.getLoginName());
            //【密码】模糊查询
            lambdaQuery.like(StringUtils.isNotEmpty(userRegister.getPassword()), UserRegister::getPassword, userRegister.getPassword());
            //【姓名】模糊查询
            lambdaQuery.like(StringUtils.isNotEmpty(userRegister.getUserName()), UserRegister::getUserName, userRegister.getUserName());
            //【工号】精确查询
            lambdaQuery.eq(StringUtils.isNotEmpty(userRegister.getUserNo()), UserRegister::getUserNo, userRegister.getUserNo());
            //【用户类型】精确查询
            lambdaQuery.eq(StringUtils.isNotNull(userRegister.getUserType()), UserRegister::getUserType, userRegister.getUserType());
            //【手机号】精确查询
            lambdaQuery.eq(StringUtils.isNotEmpty(userRegister.getPhone()), UserRegister::getPhone, userRegister.getPhone());
            //【身份证号】精确查询
            lambdaQuery.eq(StringUtils.isNotEmpty(userRegister.getIdCard()), UserRegister::getIdCard, userRegister.getIdCard());
            //【邮箱】模糊查询
            lambdaQuery.like(StringUtils.isNotEmpty(userRegister.getEmail()), UserRegister::getEmail, userRegister.getEmail());
            //【授权表id】模糊查询
            lambdaQuery.like(StringUtils.isNotEmpty(userRegister.getUserAuthorId()), UserRegister::getUserAuthorId, userRegister.getUserAuthorId());
        }
        return lambdaQuery;
    }

    //【注册信息】分页查询
    public IPage<UserRegister> getPage(Page<UserRegister> page, UserRegister userRegister) {
        LambdaQueryWrapper<UserRegister> lambdaQuery = getUserRegisterQueryCondition(userRegister);
        return userRegisterDao.selectPage(page, lambdaQuery);
    }
    
    //【注册信息】查询列表
    public List<UserRegister> getList(UserRegister userRegister) {
        LambdaQueryWrapper<UserRegister> lambdaQuery = getUserRegisterQueryCondition(userRegister);
        return userRegisterDao.selectList(lambdaQuery);
    }
    
    //【注册信息】根据id查询
    public UserRegister get(String id) {
        return userRegisterDao.selectById(id);
    }

    //【注册信息】根据对象查询
    public UserRegister get(UserRegister userRegister) {
    LambdaQueryWrapper<UserRegister> lambdaQuery = getUserRegisterQueryCondition(userRegister);
        return userRegisterDao.selectOne(lambdaQuery);
    }
    
    //【注册信息】新增
    public int insert(UserRegister userRegister) {
        this.preInsert(userRegister);
        return userRegisterDao.insert(userRegister);
    }
    
    //【注册信息】修改
    public int update(UserRegister userRegister) {
        this.preUpdate(userRegister);
        return userRegisterDao.updateById(userRegister);
    }
    
    //【注册信息】删除
    public int delete(String id) {
        return userRegisterDao.deleteById(id);
    }

}